<template>
	<view :class="AppStyle">
		<view class="msg_content">
			<view class="item">
				<text class="label">头像</text>
				<view class="value">
					<image class="logo-img" :src="require('@/static/img/user.png')"></image>
					<i class="zi zi_pathRight zi-left-margin"></i>
				</view>
			</view>
			<view class="item" @tap='changeName'>
				<text class="label">昵称</text>
				<view class="value">
					<text class="text">{{userDetail.nickName}}</text>
					<i class="zi zi_pathRight zi-left-margin"></i>
				</view>
			</view>
			<view class="item" @tap='changeSex'>
				<text class="label">性别</text>
				<view class="value">
					<text class="text">{{userDetail.sex}}</text>
					<i class="zi zi_pathRight zi-left-margin"></i>
				</view>
			</view>
			<view class="item" @tap="chagePhone">
				<text class="label">手机号码</text>
				<view class="value">
					<text class="text">{{userDetail.phone}}</text>
					<i class="zi zi_pathRight zi-left-margin"></i>
				</view>
			</view>
		</view>

		<!-- 昵称数据框 -->
		<view>
			<OneInput :showPopup="showNickNameDialog" :placeholderTxt="placeholderTxt" 
			@confirmResult="saveNickName" @hideDialog="hideDialog"></OneInput>
		</view>
		<!-- 修改/绑定手机号码 -->
		<view>
			<PhoneMsgCode :showPopup="showPhoneDialog" @resendCode="sendPhoneCode" 
			@onCommit="savePhone" @hideDialog="hidePhoneDialog"></PhoneMsgCode>
		</view>
	</view>
</template>

<script>
	import OneInput from '@/components/dialog/OneInput.vue'
	import PhoneMsgCode from '@/components/dialog/phone-msg-code.vue'

	export default {
		components: {
			OneInput,
			PhoneMsgCode
		},
		data() {
			return {
				AppStyle: 'bg-wite-page commom-margin',
				showNickNameDialog: false,
				placeholderTxt: '',
				userDetail: {
					logo: '',
					nickName: '',
					sex: '',
					birth: '',
					phone: '18253594233'
				},
				showPhoneDialog: false
			}
		},
		methods: {
			sendPhoneCode(phoneNum) {
				//调用接口发送验证码
				console.info("发送验证码" + phoneNum)
			},
			chagePhone() {
				this.showPhoneDialog = true
			},
			changeName() {
				this.showNickNameDialog = true
				this.placeholderTxt = '您的昵称'
			},
			saveNickName(val) {
				this.showNickNameDialog = false
				console.info(val)
				this.userDetail.nickName = val
			},
			hideDialog() {
				this.showNickNameDialog = false
			},
			hidePhoneDialog() {
				this.showPhoneDialog = false
			},
			savePhone(phone, code) {
				console.info("手机号码:" + phone + ",验证码:" + code)
				this.showPhoneDialog = false
			},
			changeSex() {
				const arr = ['男', '女', '保密']
				uni.showActionSheet({
					itemList: arr,
					success: (res) => {
						this.userDetail.sex = arr[res.tapIndex]
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		display: flex;
		flex-direction: row;
		align-items: center;
		border-bottom: 1px solid #eee;
		padding-top: 28rpx;
		padding-bottom: 28rpx;

		.label {
			font-size: 28rpx;
			color: #606266;
		}

		.value {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-end;
			flex: 1;

			.logo-img {
				border-radius: 50%;
				width: 60rpx;
				height: 60rpx;
				overflow: visible;
				opacity: 1;
				transition: opacity 0.5s ease-in-out 0s;
				background-color: transparent;
			}

			.text {
				color: #909399;
			}

			.zi-left-margin {
				margin-left: 10rpx;
				color: #909399;
			}
		}
	}
</style>
